﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Waiter.View
{
    public partial class FrmMenu : DevComponents.DotNetBar.Office2007Form//Form
    {        
        FrmCouponDetials myfrmCouponDetials = null;
        frmGroupList myfrmGroupList = null;
        frmHoursWork_Edit myfrmHourWork_Edit = null;
        frmHoursWork_RefList myfrmHourWork_RefList = null;        
        FrmOrderCoupon myfrmOrderCoupon = null;
        frmSalary myfrmSalary = null;
        frmSalaryCalc myfrmSalaryCalc = null;
        FrmSales myfrmSale = null;
        frmStaff myfrmStaff = null;
        FrmUser myfrmUser = null;
        frmWorkShifts myfrmWorkShift = null;
        FrmSales myFrmSales = null;
        frmPayment myfrmPayment = null;
        FrmOtherRevenue myFrmOtherRevenue = null;
        FrmTables myFrmTables = null;
        FrmMenuItems myFrmMenuItem = null;
        frmRptSalary myRptSalary = null;
        Waiter.Common.UserType myCurrentUserType;

        public FrmMenu()
        {
            InitializeComponent();            
        }

        private void btnStaff_Click(object sender, EventArgs e)
        {  
            if (this.myfrmStaff == null || this.myfrmStaff.IsDisposed)
            {
                this.myfrmStaff = new frmStaff();
                this.myfrmStaff.Show();
            }
            else
            {
                this.myfrmStaff.Focus();
            }
        }

        private void btnWorkShift_Click(object sender, EventArgs e)
        {
            if (this.myfrmWorkShift == null || this.myfrmWorkShift.IsDisposed)
            {
                this.myfrmWorkShift = new frmWorkShifts();
                this.myfrmWorkShift.Show();
            }
            else
            {
                this.myfrmWorkShift.Focus();
            }
        }

        private void btnHourWork_Click(object sender, EventArgs e)
        {
            if (this.myfrmHourWork_Edit == null || this.myfrmHourWork_Edit.IsDisposed)
            {
                this.myfrmHourWork_Edit = new frmHoursWork_Edit();
                this.myfrmHourWork_Edit.Show();
            }
            else
            {
                this.myfrmHourWork_Edit.Focus();
            }
        }


        private void btnHourWorkList_Click(object sender, EventArgs e)
        {
            if (this.myfrmHourWork_RefList == null || this.myfrmHourWork_RefList.IsDisposed)
            {
                this.myfrmHourWork_RefList = new frmHoursWork_RefList();
                this.myfrmHourWork_RefList.Show();
            }
            else
            {
                this.myfrmHourWork_RefList.Focus();
            }
        }

        private void btnSalaryCalc_Click(object sender, EventArgs e)
        {
            if (this.myfrmSalaryCalc == null || this.myfrmHourWork_RefList.IsDisposed)
            {
                this.myfrmSalaryCalc = new frmSalaryCalc();
                this.myfrmSalaryCalc.Show();
            }
            else
            {
                this.myfrmSalaryCalc.Focus();
            }
        }


        private void btnSalaryChange_Click(object sender, EventArgs e)
        {

            if (this.myfrmSalary == null || this.myfrmSalary.IsDisposed)
            {
                this.myfrmSalary = new frmSalary();
                this.myfrmSalary.Show();
            }
            else
            {
                this.myfrmSalary.Focus();
            }
        }


        private void btnUser_Click(object sender, EventArgs e)
        {
            if (this.myfrmUser == null || this.myfrmUser.IsDisposed)
            {
                this.myfrmUser = new FrmUser();
                this.myfrmUser.Show();
            }
            else
            {
                this.myfrmUser.Focus();
            }
        }

        private void btnGroupList_Click(object sender, EventArgs e)
        {
            if (this.myfrmGroupList == null || this.myfrmGroupList.IsDisposed)
            {
                this.myfrmGroupList = new frmGroupList();
                this.myfrmGroupList.Show();
            }
            else
            {
                this.myfrmGroupList.Focus();
            }
        }


        private void headerItem1_Load(object sender, EventArgs e)
        {
            this.headerItem1.init("CHỨC NĂNG", true);
        }

        private void FrmMenu_Load(object sender, EventArgs e)
        {
            this.Hide();
            frmLogin frm = new frmLogin();

            if (frm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.fsControlFunctionAction();
                this.Show();
            }
            else
            {
                Application.Exit();
            }
        }

        public void fsControlFunctionAction()
        {
            if (Properties.Settings.Default.USER_TYPE == 1)
            {
                myCurrentUserType = Common.UserType.ADMIN;
                fpnlBusiness.Enabled = true;
                fpnlManage.Enabled = true;
                fpnlReport.Enabled = true;
                fpnlStaff.Enabled = true;
                btnBanHang.Enabled = true;
                btnMenu.Enabled = true;
                btnTableList.Enabled = true;
                btnOtherRevenue.Enabled = true;
                btnPayment.Enabled = true;
            }
            else
            {
                myCurrentUserType = Common.UserType.USER;
                fpnlBusiness.Enabled = true;
                fpnlManage.Enabled = false;
                fpnlReport.Enabled = false;
                fpnlStaff.Enabled = false;
                btnBanHang.Enabled = true;
                btnMenu.Enabled = false;
                btnTableList.Enabled = false;
                btnOtherRevenue.Enabled = false;
                btnPayment.Enabled = false;
            }
        }

        private void btnBanHang_Click(object sender, EventArgs e)
        {
            if (this.myFrmSales == null || this.myFrmSales.IsDisposed)
            {
                this.myFrmSales = new FrmSales();
                this.myFrmSales.Show();
            }
            else
            {
                this.myFrmSales.Focus();
            }
        }
        
        private void buttonX3_Click(object sender, EventArgs e)
        {
            if (this.myFrmMenuItem == null || this.myFrmMenuItem.IsDisposed)
            {
                this.myFrmMenuItem = new FrmMenuItems();
                this.myFrmMenuItem.Show();
            }
            else
            {
                this.myFrmMenuItem.Focus();
            }
        }

        
        private void buttonX5_Click(object sender, EventArgs e)
        {
            if (this.myFrmTables == null || this.myFrmTables.IsDisposed)
            {
                this.myFrmTables = new FrmTables();
                this.myFrmTables.Show();
            }
            else
            {
                this.myFrmTables.Focus();
            }
        }

        
        private void buttonX2_Click(object sender, EventArgs e)
        {
            if (this.myFrmOtherRevenue == null || this.myFrmOtherRevenue.IsDisposed)
            {
                this.myFrmOtherRevenue = new FrmOtherRevenue();
                this.myFrmOtherRevenue.Show();
            }
            else
            {
                this.myFrmOtherRevenue.Focus();
            }
        }

        private void btnPayment_Click(object sender, EventArgs e)
        {
            if (this.myfrmPayment == null || this.myfrmPayment.IsDisposed)
            {
                this.myfrmPayment = new frmPayment();
                this.myfrmPayment.Show();
            }
            else
            {
                this.myfrmPayment.Focus();
            }
        }

        private void btnReportSalary_Click(object sender, EventArgs e)
        {
            if (this.myRptSalary == null || this.myRptSalary.IsDisposed)
            {
                this.myRptSalary = new frmRptSalary();
                this.myRptSalary.Show();
            }
            else
            {
                this.myRptSalary.Focus();
            }
        }


        /// <summary>
        /// Thay đổi các chức năng được sử dụng (trong trường hợp thay đổi user)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timeChangeUserType_Tick(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.USER_TYPE == 1)
            {
                if (myCurrentUserType == Common.UserType.USER)
                {
                    this.fsControlFunctionAction();
                }
            }
            else
            {
                if (myCurrentUserType == Common.UserType.ADMIN)
                {
                    this.fsControlFunctionAction();
                }
            }    
        }

        FrmRptRevenue myRptRevenue = null;
        private void btnRptRevenue_Click(object sender, EventArgs e)
        {
            if (this.myRptRevenue == null || this.myRptRevenue.IsDisposed)
            {
                this.myRptRevenue = new FrmRptRevenue();
                this.myRptRevenue.Show();
            }
            else
            {
                this.myRptRevenue.Focus();
            }
        }

        frmRptSaleNumber myRptSaleNumber = null;
        private void btnRptSalesNumber_Click(object sender, EventArgs e)
        {
            if (this.myRptSaleNumber == null || this.myRptSaleNumber.IsDisposed)
            {
                this.myRptSaleNumber = new frmRptSaleNumber();
                this.myRptSaleNumber.Show();
            }
            else
            {
                this.myRptSaleNumber.Focus();
            }
        }

        FrmRptBill myRptBill = null;
        private void btnBill_Click(object sender, EventArgs e)
        {
            if (this.myRptBill == null || this.myRptBill.IsDisposed)
            {
                this.myRptBill = new FrmRptBill();
                this.myRptBill.Show();
            }
            else
            {
                this.myRptBill.Focus();
            }
        }

        FrmFuniture frmFuniture = null;
        private void btnFuniture_Click(object sender, EventArgs e)
        {
            if (this.frmFuniture == null || this.frmFuniture.IsDisposed)
            {
                this.frmFuniture = new FrmFuniture();
                this.frmFuniture.Show();
            }
            else
            {
                this.frmFuniture.Focus();
            }
        }

    }
}
